//------------------------------------------------------------------------------
// The contents of this file are subject to the nopCommerce Public License Version 1.0 ("License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at  http://www.nopCommerce.com/License.aspx. 
// 
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
// See the License for the specific language governing rights and limitations under the License.
// 
// The Original Code is nopCommerce.
// The Initial Developer of the Original Code is NopSolutions.
// All Rights Reserved.
// 
// Contributor(s): _______. 
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Text;
using Tathata.Common.Caching;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using System.Globalization;
using Tathata.Common.DAL;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.EntityCollections;
using Tathata.Common.DAL.Managers;

namespace Tathata.Common.BLL.Managers
{
    /// <summary>
    /// Product variant attribute value manager
    /// </summary>
    public class ProductVariantAttributeValueManager
    {
        #region Constants
        private const string PRODUCTVARIANTATTRIBUTEVALUES_ALL_KEY = "Nop.productvariantattributevalue.all-{0}";
        private const string PRODUCTVARIANTATTRIBUTEVALUES_BY_ID_KEY = "Nop.productvariantattributevalue.id-{0}";
        #endregion

        #region Methods
        /// <summary>
        /// Deletes a product variant attribute value
        /// </summary>
        /// <param name="ProductVariantAttributeValueID">Product variant attribute value identifier</param>
        public static void DeleteProductVariantAttributeValue(int ProductVariantAttributeValueID)
        {
            ProductVariantAttributeValueDBManager.DeleteProductVariantAttributeValue(ProductVariantAttributeValueID);
            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_ALL_KEY);
                NopCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_BY_ID_KEY);
            }
        }

        /// <summary>
        /// Gets product variant attribute values by product identifier
        /// </summary>
        /// <param name="ProductVariantAttributeID">The product variant attribute mapping identifier</param>
        /// <returns>Product variant attribute mapping collection</returns>
        public static ProductVariantAttributeValueCollection GetAllByByProductVariantAttributeID(int ProductVariantAttributeID)
        {
            string key = string.Format(PRODUCTVARIANTATTRIBUTEVALUES_ALL_KEY, ProductVariantAttributeID);
            object obj2 = NopCache.Get(key);
            if (NopContext.IsCachable && (obj2 != null))
            {
                return (ProductVariantAttributeValueCollection)obj2;
            }

            ProductVariantAttributeValueCollection productVariantAttributeValues = ProductVariantAttributeValueDBManager.GetAllByByProductVariantAttributeID(ProductVariantAttributeID);
            if (NopContext.IsCachable)
            {
                NopCache.Max(key, productVariantAttributeValues);
            }
            return productVariantAttributeValues;
        }

        /// <summary>
        /// Gets a product variant attribute value
        /// </summary>
        /// <param name="ProductVariantAttributeValueID">Product variant attribute value identifier</param>
        /// <returns>Product variant attribute value</returns>
        public static ProductVariantAttributeValue GetByProductVariantAttributeValueID(int ProductVariantAttributeValueID)
        {
            string key = string.Format(PRODUCTVARIANTATTRIBUTEVALUES_BY_ID_KEY, ProductVariantAttributeValueID);
            object obj2 = NopCache.Get(key);
            if (NopContext.IsCachable && (obj2 != null))
            {
                return (ProductVariantAttributeValue)obj2;
            }

            ProductVariantAttributeValue productVariantAttributeValue = ProductVariantAttributeValueDBManager.GetByProductVariantAttributeValueID(ProductVariantAttributeValueID);

            if (NopContext.IsCachable)
            {
                NopCache.Max(key, productVariantAttributeValue);
            }
            return productVariantAttributeValue;
        }

        /// <summary>
        /// Inserts a product variant attribute value
        /// </summary>
        /// <param name="ProductVariantAttributeID">The product variant attribute mapping identifier</param>
        /// <param name="Name">The product variant attribute name</param>
        /// <param name="PriceAdjustment">The price adjustment</param>
        /// <param name="DisplayOrder">The display order</param>
        /// <returns>Product variant attribute value</returns>
        public static ProductVariantAttributeValue InsertProductVariantAttributeValue(int ProductVariantAttributeID,
            string Name, decimal PriceAdjustment, int DisplayOrder)
        {
            ProductVariantAttributeValue productVariantAttributeValue = ProductVariantAttributeValueDBManager.InsertProductVariantAttributeValue(ProductVariantAttributeID,
                Name, PriceAdjustment, DisplayOrder);

            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_ALL_KEY);
                NopCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_BY_ID_KEY);
            }

            return productVariantAttributeValue;
        }


        /// <summary>
        /// Updates the product variant attribute value
        /// </summary>
        /// <param name="ProductVariantAttributeValueID">The product variant attribute value identifier</param>
        /// <param name="ProductVariantAttributeID">The product variant attribute mapping identifier</param>
        /// <param name="Name">The product variant attribute name</param>
        /// <param name="PriceAdjustment">The price adjustment</param>
        /// <param name="DisplayOrder">The display order</param>
        /// <returns>Product variant attribute value</returns>
        public static ProductVariantAttributeValue UpdateProductVariantAttributeValue(int ProductVariantAttributeValueID,
            int ProductVariantAttributeID, string Name, decimal PriceAdjustment, int DisplayOrder)
        {
            ProductVariantAttributeValue productVariantAttributeValue = ProductVariantAttributeValueDBManager.UpdateProductVariantAttributeValue(ProductVariantAttributeValueID,
                ProductVariantAttributeID, Name, PriceAdjustment, DisplayOrder);

            if (NopContext.IsCachable)
            {
                NopCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_ALL_KEY);
                NopCache.RemoveByPattern(PRODUCTVARIANTATTRIBUTEVALUES_BY_ID_KEY);
            }

            return productVariantAttributeValue;
        }

        #endregion
    }
}
